package group2assignone.ucm.customer;

import group2assignone.dao.MyDAO;
import group2assignone.model.Airport;
import group2assignone.model.Customer;
import group2assignone.ucm.UCController;
import group2assignone.ucm.UCStartup;
import group2assignone.view.OurView;
import group2assignone.view.customer.SearchFlightsView;
import java.util.ArrayList;

/**
 * Use Case: Change UI to Search Flights<br>
 * Pre-condition: User clicks the 'search flight' (from main menu or from customer options).<br>
 * Post-condition: Search Flights view is displayed.<br>
 * 1. system gets the airports to search from
 * 2. system creates the new Search Flights view<br>
 * 3. system opens the new Search Flights view<br>
 * 4. system exits the current view<br>
 * @author group2
 */
public class UCChangeUISearchFlights implements UCController {

    private OurView view;
    private Customer customer;
    private ArrayList<Airport> airports = new ArrayList<Airport>();
    private MyDAO coms;

    /**
     * The customer field is used for personalisation of view.
     * @param view
     * @param customer
     */
    public UCChangeUISearchFlights(OurView view, Customer customer) {
        this.view = view;
        this.customer = customer;
        coms = UCStartup.getInstance().getDAO();
    }

    /**
     * The customer is not logged in, a guest customer is created.
     * @param view
     */
    public UCChangeUISearchFlights(OurView view) {
        this.view = view;
        customer = new Customer();
        customer.setUsername("Guest");
        coms = UCStartup.getInstance().getDAO();
    }

    /**
     * Use Case to update the gui to display the Search Flights view.
     */
    public void run() {
        //1. system gets the airports to search from
        airports = coms.sQLGetAirports();
        // 2. system creates the new Search Flights view
        SearchFlightsView gui = new SearchFlightsView(customer, airports);
        gui.go();       // 3. system opens the new Search Flights view
        view.dispose(); // 4. system exits the current view
    }
}
